<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script crossorigin="anonymous" src="https://cdn.bootcdn.net/ajax/libs/axios/0.26.1/axios.js"></script>
    </head>
    <body>
            <button>GET</button>
            <button>POST</button>
            <button>AJAX</button>
            <script type="text/javascript">
                const btns = document.querySelectorAll("button");
                axios.defaults.baseURL = "http://127.0.0.1:8000";
                btns[0].onclick = function(){
                    axios.get("/axios-server",{
                        //url参数
                        params:{
                            id:123456
                        },
                        //请求头信息
                        headers:{
                            name:"wangteng",
                            age:22
                        }
                    });
                }
                btns[1].onclick = function(){
                    axios.post("/axios-server",{
                            username:"wt",
                            password:"123"
                    },{
                         params: {
                                id: 1234567
                            },
                            //请求头信息
                            headers: {
                                name:"shang",
                                age: 22
                            }
                    }).then(response =>{
                        console.log(response);
                    });
                };
                
                btns[2].onclick = function(){
                    axios({
                        method:"post",
                        url:"/axios-server",
                        params:{
                            id:10
                        },
                        headers:{
                            a:100,
                            b:200
                        },
                        data:{
                            username: "wt",
                            password: "123"
                        }
                    }).then(response => {
                        console.log(response.status);
                        console.log(response.statusText);
                        console.log(response.data);
                    });
                }
            
            </script>   
    </body>
</html>